package com.zhang.thread;

import java.util.concurrent.CountDownLatch;

/**
 * @author : [WangWei]
 * @version : [v1.0]
 * @className : CalaulationStudentsData
 * @description : [计算学生学习数据]
 * @createTime : [2022/12/28 9:24]
 * @updateUser : [WangWei]
 * @updateTime : [2022/12/28 9:24]
 * @updateRemark : [描述说明本次修改内容]
 */
public class CalculationStudentsData implements Runnable{
    int studentNumber;
    CountDownLatch latch;

    /*
     * @version V1.0
     * Title: CalculationStudentsData
     * @author Wangwei
     * @description 构造函数中传入学生编号
     * @createTime  2022/12/28 9:29
     * @param [studentNumber]
     * @return
     */
    public CalculationStudentsData(int studentNumber, CountDownLatch latch){
        this.studentNumber=studentNumber;
        this.latch=latch;
    }
    /*
     * @version V1.0
     * Title: run
     * @author Wangwei
     * @description 执行线程
     * @createTime  2022/12/28 9:30
     * @param []
     * @return void
     */
    @Override
    public void run() {
        try {
            //计算学生学习数据的方法
            this.CalculationStudentData();
            //计数器减一
            latch.countDown();
        }catch (Exception e){
        	//计数器减一，避免死循环
            latch.countDown();
            
        }
    }
    /*
     * @version V1.0
     * Title: CalaulationStudentData
     * @author Wangwei
     * @description 计算学生学习数据的方法
     * @createTime  2022/12/28 9:32
     * @param []
     * @return void
     */
    private void CalculationStudentData(){
    	//输出学生编号和执行该任务的线程名称
        System.out.println("完成学生"+studentNumber+"的学习成绩计算"+Thread.currentThread().getName());
    }
}

